package com.example.coroutines

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext

/**
 * @author yaotianxue
 * @description
 * @date 2024/10/17
 */
fun main(){
    //创建顶层协程
    runBlocking {
        //子协程
        launch {
            withContext(Dispatchers.IO){
                System.out.println("协程工作了1"+Thread.currentThread().name)
                delay(3000)
            }

        }
        launch {
            System.out.println("协程工作了2"+Thread.currentThread().name)
            delay(2000)
        }
        launch {
            System.out.println("协程工作了3"+Thread.currentThread().name)
            delay(2000)
        }
    }
}